package com.jiayan.controller;

import com.jiayan.service.CartService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;

@Controller
@RequestMapping("/cart")
public class CartController {
    @Resource
    private CartService cartService;

    @RequestMapping("/add_cart")
    public String addCar(Integer pid, HttpServletRequest request){
        boolean result = cartService.addCar(pid,request);
        if(!result){//为空处理

        }
        return "redirect:/goods/detail?pid="+pid;
    }
    @RequestMapping("/tocart")
    public String toShopping(){ return "cart";}

    @RequestMapping("/changeNum")
    public String changeNum(@RequestParam(value = "ep_id")Integer epId, BigDecimal amount, Integer newNum, HttpServletRequest request){
        boolean result =cartService.changeNum(epId,amount,newNum,request);
        return "Num";
    }

    @RequestMapping("/order")
    public String order(HttpServletRequest request){
        boolean res = cartService.createOrder(request);
        return "result";
    }


}
